package br.com.social.mobile.dao;

import java.util.Date;

import javax.persistence.Query;

import org.apache.log4j.Logger;

import br.com.social.mobile.entities.ChatGroup;
import br.com.social.mobile.entities.Profile;


public class ChatGroupDAO extends GenericDAO<ChatGroup>{
	
	private Logger logger = Logger.getLogger(ChatGroupDAO.class);
	 
	
	
	public void updateStatusChat (long nuIdChat, long nuIdUser, Boolean flgActive){
		
		try {
			createEntityManager();
			Query query = entityManager
					.createNativeQuery("update tb_chat_group set flg_active = :flgActive, dt_last_update = :dtLastUpdate "
							+ "where nu_id_chat = :nuIdChat and nu_id_user = :nuIdUser")
					.setParameter("flgActive", flgActive)
					.setParameter("dtLastUpdate", new Date())
					.setParameter("nuIdChat", nuIdChat)
					.setParameter("nuIdUser", nuIdUser);

            entityManager.getTransaction().begin();
			query.executeUpdate();
            entityManager.getTransaction().commit();
						
		} catch (Exception e) {
			logger.error(e);
		}	
		
	}
	

	
}
